package com.cppba.mapper.provider;

import org.apache.commons.lang3.StringUtils;

// 动态生成sql
public class UserMapperProvider {

	public static final String BASE_SELECT = " u.id, u.delete_status, u.username, u.password, u.city_id, u.sex ";



	public String getById(Long id) {
		String sql = "SELECT " + BASE_SELECT + ", c.name as cityName FROM user u LEFT JOIN city c on u.city_id = c.id where u.id = #{id} ";
		return sql;
	}

	public String page(String username) {
		String sql = " SELECT " + BASE_SELECT + ", c.name as cityName FROM user u LEFT JOIN city c on u.city_id = c.id where u.delete_status = 0 ";
		if (StringUtils.isNotBlank(username)) {
			sql += " and u.username LIKE concat('%',#{username},'%') ";
		}
		return sql;
	}
}
